import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class MatrixPanel extends JPanel {
	
	private JPanel matrixSelectPanel;
	private JPanel matrixDisplayPanel;
	private JPanel selectedMatrixPanel;
	private JComboBox matrixHeightBox;
	private JComboBox matrixWidthBox;
	private Integer[] height = {1, 2 , 3, 4, 5};
	private Integer[] width = {1, 2, 3, 4, 5};
	private JLabel label1;
	private JLabel label2;
	private JLabel space1;
	private JLabel space2;
	private JButton buildButton;
	private int selectionH;
	private int selectionW;
	
	private double[][] matrix; 
	
	public MatrixPanel()
	{	
		this.setBackground(Color.red);
		this.setLayout(new BorderLayout());		
		
		buildMatrixSelectPanel();
		buildMatrixDisplayPanel();
		
		add(matrixSelectPanel, BorderLayout.NORTH);
		add(matrixDisplayPanel, BorderLayout.CENTER);
		
		setVisible(true);
		
	}
	
	/*
	public void paint(Graphics g){
		super.paint(g);
		
		g.setColor(Color.BLACK);
		
		g.drawLine(100, 100, 100, 200);
		g.drawLine(100, 100, 105, 100);
		g.drawLine(100, 200, 105, 200);
		
		g.drawLine(400, 100, 400, 200);
		g.drawLine(400, 100, 395, 100);
		g.drawLine(400, 200, 395, 200);	
	}*/
	
	private void buildMatrixSelectPanel(){
		matrixSelectPanel = new JPanel();
		buildButton = new JButton("Build Matrix");
		
		buildButton.addActionListener(new buildButtonListener());
		
		label1 = new JLabel("Matrix Height: ");
		label2 = new JLabel("\t\tMatrix Width: ");
		space1 = new JLabel("             ");
		space2 = new JLabel("             ");
		
		matrixHeightBox = new JComboBox(height);
		matrixWidthBox = new JComboBox(width);
		
		matrixHeightBox.addActionListener(new ComboBoxListener());
		matrixWidthBox.addActionListener(new ComboBoxListener());
		matrixSelectPanel.add(label1);
		matrixSelectPanel.add(matrixHeightBox);
		matrixSelectPanel.add(space1);
		matrixSelectPanel.add(label2);
		matrixSelectPanel.add(matrixWidthBox);
		matrixSelectPanel.add(space2);
		matrixSelectPanel.add(buildButton);
	}
	
	private void buildMatrixDisplayPanel(){
		matrixDisplayPanel = new JPanel();
	}
	
	private class ComboBoxListener implements ActionListener{

		public void actionPerformed(ActionEvent e) {
			selectionH = (Integer)matrixHeightBox.getSelectedItem();
			selectionW = (Integer)matrixWidthBox.getSelectedItem();
			
			matrix = new double [selectionH][selectionW];
			
			/*
			for(int i=0; i<selectionH; i++){
				for(int j=0; j<selectionW; j++){
					JTextField temp = new JTextField(4);
					matrixDisplayPanel.add(temp);
					matrixDisplayPanel.add(spacing);
				}
			}*/
			
			//matrixDisplayPanel.updateUI();
			
			//Matrix.matrixPrint(matrix);
			
			
			
		}
	}
	
	private class buildButtonListener implements ActionListener{
		public void actionPerformed(ActionEvent e){
			
			JLabel spacing = new JLabel("    ");
			
			for(int i=0; i<selectionH; i++){
				for(int j=0; j<selectionW; j++){
					JTextField temp = new JTextField(4);
					matrixDisplayPanel.add(temp);
					matrixDisplayPanel.add(spacing);
				}
				//matrixDisplayPanel.
			}
			
			matrixDisplayPanel.updateUI();
		}
	}
	
	
}
